<template>
  <el-dialog
    width="63%"
    :title="'上报记录'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <div class="mod-config">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
          <!--        <el-button v-if="isAuth('generator:bsdepartmentpatient:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
          <!--        <el-button v-if="isAuth('generator:bsdepartmentpatient:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <el-table-column
          prop="imgType"
          header-align="center"
          align="center"
          label="照片类型">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.imgType === 1" size="small" type="success">入院照片</el-tag>
            <el-tag v-else type="info" size="small">上报照片</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="patientImg"
          header-align="center"
          align="center"
          label="照片">
          <template slot-scope="scope">
            <el-popover v-if="scope.row.imgType === 2" placement="right" trigger="hover">
              <img v-if="scope.row.patientImg" :src="baseUrl + scope.row.patientImg" style="width: 400px;">
              <img v-if="scope.row.patientImg" slot="reference" :src="baseUrl + scope.row.patientImg"
                   style="width: 120px;height: 80px">
            </el-popover>
            <img v-else slot="reference" :src="baseUrl + scope.row.patientImg" style="width: 120px;height: 80px">
          </template>
        </el-table-column>
        <el-table-column
          prop="photographDate"
          header-align="center"
          align="center"
          label="拍照日期">
        </el-table-column>
        <el-table-column
          prop="createTime"
          header-align="center"
          align="center"
          label="上传日期">
        </el-table-column>
        <!--        <el-table-column-->
        <!--          prop="extract_detailPatientId"-->
        <!--          header-align="center"-->
        <!--          align="center"-->
        <!--          label="是否抽查">-->
        <!--        </el-table-column>-->
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <!--      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>-->
    </span>
  </el-dialog>
</template>

<script>
    export default {
        data() {
            return {
                baseUrl: this.$http.adornUrl("/app/file/down"),
                visible: false,
                dataForm: {
                    key: ''
                },
                department_patient_id: '',
                dataList: [],
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                dataListLoading: false,
                dataListSelections: [],
            }
        },
        // activated() {
        //     this.getDataList()
        // },
        methods: {
            // 获取数据列表
            getDataList() {
                this.dataListLoading = true
                this.$http({
                    url: this.$http.adornUrl('/bs/departmentPatientImg/list'),
                    method: 'get',
                    params: this.$http.adornParams({
                        'page': this.pageIndex,
                        'limit': this.pageSize,
                        'department_patient_id': this.department_patient_id,
                        'key': this.dataForm.key
                    })
                }).then(({data}) => {
                    if (data && data.code === 0) {
                        this.dataList = data.page.list
                        this.totalPage = data.page.totalCount
                    } else {
                        this.dataList = []
                        this.totalPage = 0
                    }
                    this.dataListLoading = false
                })
            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val
                this.pageIndex = 1
                this.getDataList()
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val
                this.getDataList()
            },
            // 多选
            selectionChangeHandle(val) {
                this.dataListSelections = val
            },
            init(id) {
                this.visible = true
                this.department_patient_id = id;
                this.getDataList();
            },
        }
    }
</script>
